package com.example.controller;
import com.example.Service.MoodDiaryService;
import com.example.entity.MoodDiary;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/mood")
@CrossOrigin(origins = "*")
public class MoodDiaryController {

    @Autowired
    private MoodDiaryService moodDiaryService;

    @PostMapping("/add")
    public String addDiary(@RequestBody MoodDiary diary) {
        return moodDiaryService.addDiary(diary) > 0 ? "success" : "fail";
    }

    @DeleteMapping("/delete/{diaryId}")
    public String deleteDiary(@PathVariable Integer diaryId) {
        return moodDiaryService.deleteDiaryById(diaryId) > 0 ? "success" : "fail";
    }

    @PutMapping("/update")
    public String updateDiary(@RequestBody MoodDiary diary) {
        return moodDiaryService.updateDiary(diary) > 0 ? "success" : "fail";
    }

    @GetMapping("/user/{userId}")
    public List<MoodDiary> getDiariesByUserId(@PathVariable Integer userId) {
        return moodDiaryService.getDiariesByUserId(userId);
    }
}
